/*
* Copyright (C) 2023 ~ 2033 Ltd.
*
* Author:     helei <2454264168@qq.com>
*
* Maintainer: helei <2454264168@qq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* General Public License version 3 as published by the Free Software
* Foundation and appearing in the file LICENSE.MIT included in the
* packaging of this file.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ULINEEDIT_H
#define ULINEEDIT_H

#include "utkwidget_export.h"

#include <QLineEdit>
#include <QPushButton>

class ULineEditButton : public QPushButton
{
public:
    ULineEditButton(QWidget* parent = Q_NULLPTR);

    void setRadius(int radius);

    void setBackGroundColor(const QColor &color);

protected:
    void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;

private:
    QColor m_color = QColor();
    int m_radius = 8;
};

class ULineEditPrivate;
class UTKWIDGET_EXPORT ULineEdit : public QLineEdit
{
    Q_OBJECT
public:
    explicit ULineEdit(QWidget* parent = nullptr);
    explicit ULineEdit(const QString &text, QWidget* parent = nullptr);
    ~ULineEdit() override;

    void setHoverEnabled(bool enabled);

    void setBorderWidth(double width);

    void setRadius(int radius);

    bool openCloseButton();

    void setOpenCloseButton(bool isOpen);

    void addLeftAction(const QIcon &icon, const QSize &iconSize);

    void addLeftAction(const QString &text);

    void clearAction();

    bool isAlert();

    void showAlertMessage(const QString &text, int duration = 3000);

    void hideAlertMessage();

signals:
    void closeButtonClicked();

protected:
    void paintEvent(QPaintEvent* event) override;

    void resizeEvent(QResizeEvent* event) override;

    void mousePressEvent(QMouseEvent *) override;

    void mouseMoveEvent(QMouseEvent *) override;

    void mouseReleaseEvent(QMouseEvent *) override;

private:
    QScopedPointer<ULineEditPrivate> d_ptr;
    Q_DISABLE_COPY(ULineEdit)
    Q_DECLARE_PRIVATE_D(d_ptr, ULineEdit)
};

#endif // ULINEEDIT_H
